var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var n in t) t.hasOwnProperty(n) && (e[n] = t[n]);
    })(e, t);
}, function(e, t) {
    function n() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, 
    new n());
}), a = this && this.__decorate || function(e, t, n, a) {
    var o, s = arguments.length, i = s < 3 ? t : null === a ? a = Object.getOwnPropertyDescriptor(t, n) : a;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) i = Reflect.decorate(e, t, n, a); else for (var r = e.length - 1; 0 <= r; r--) (o = e[r]) && (i = (s < 3 ? o(i) : 3 < s ? o(t, n, i) : o(t, n)) || i);
    return 3 < s && i && Object.defineProperty(t, n, i), i;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("GameManager"), s = e("AudioManager"), c = e("Global"), l = e("PlayerModel"), d = e("ItemManager"), u = cc._decorator, p = u.ccclass, h = (u.property, 
function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.skeleton = null, e.sprite = null, e.shadow = null, e.type = c.ItemType.BUFFER, 
        e.data = null, e.isPlay = !1, e.isDestory = !1, e;
    }
    return i(e, t), e.prototype.init = function(e, t) {
        var n = this;
        switch (this.type = e, this.data = t, this.type) {
          case c.ItemType.BUFFER:
            this.isPlay = !0, r.default.getInstance().gameView.appendSkeleton({
                url: this.getBufferUrl(t.type),
                root: r.default.getInstance().gameView.layout,
                pos: this.node.getPosition().add(cc.v2(0, 500))
            }).then(function(e) {
                (n.skeleton = e) instanceof sp.Skeleton && !n.isDestory ? (s.default.getInstance().playAudio("道具落地音效"), 
                n.skeleton.node.zIndex = n.node.zIndex, n.skeleton.node.active = !0, n.skeleton.node.scale = 3, 
                cc.tween(n.skeleton.node).parallel(cc.tween().to(.6, {
                    scale: 1
                }), cc.tween().by(.6, {
                    position: cc.v2(0, -500)
                })).to(.1, {
                    scale: 1.1
                }).to(.1, {
                    scale: 1
                }).call(function() {
                    n.isPlay = !1, n.skeleton.setAnimation(0, "animation", !0);
                }).start()) : n && n.doDestory();
            });
            break;

          case c.ItemType.CHRISTMAS:
            r.default.getInstance().gameView.appendSprite({
                url: this.getChristmasUrl(t.type, t.idx),
                root: r.default.getInstance().gameView.layout,
                pos: this.node.getPosition().add(cc.v2(0, 500))
            }).then(function(e) {
                (n.sprite = e) instanceof cc.Sprite && !n.isDestory ? (n.sprite.node.angle = 0, 
                n.sprite.node.scale = 1, n.sprite.node.zIndex = n.node.zIndex, n.sprite.node.active = !0, 
                e = 3 == n.data.type || 2 == n.data.type ? .5 : .8, n.sprite.node.scale = 3 * e, 
                cc.tween(n.sprite.node).parallel(cc.tween().to(.6, {
                    scale: 1
                }), cc.tween().by(.6, {
                    position: cc.v2(0, -485)
                })).to(.1, {
                    scale: 1.1 * e
                }).to(.1, {
                    scale: e
                }).call(function() {
                    n.isPlay = !1;
                }).repeatForever(cc.tween().by(1, {
                    position: cc.v2(0, 15)
                }).by(1, {
                    position: cc.v2(0, -15)
                })).start()) : n && n.doDestory();
            }), r.default.getInstance().gameView.appendSprite({
                url: "texture/battle/shadow",
                root: r.default.getInstance().gameView.bottom,
                pos: this.node.getPosition().add(cc.v2(0, -20))
            }).then(function(e) {
                n.isDestory ? r.default.getInstance().gameView.removeSprite(e.node) : (n.shadow = e.node, 
                e.node.active = !0, e.node.scale = .4, e.node.angle = 0, e.node.zIndex = -2);
            });
            break;

          case c.ItemType.NEWYEAR:
            r.default.getInstance().gameView.appendSprite({
                url: this.getNewYearUrl(t.type, t.idx),
                root: r.default.getInstance().gameView.layout,
                pos: this.node.getPosition().add(cc.v2(0, 500))
            }).then(function(e) {
                (n.sprite = e) instanceof cc.Sprite && !n.isDestory ? (n.sprite.node.angle = 0, 
                n.sprite.node.scale = 1, n.sprite.node.zIndex = n.node.zIndex, n.sprite.node.active = !0, 
                e = 3 == n.data.type || 2 == n.data.type ? .5 : .8, n.sprite.node.scale = 3 * e, 
                cc.tween(n.sprite.node).parallel(cc.tween().to(.6, {
                    scale: 1
                }), cc.tween().by(.6, {
                    position: cc.v2(0, -485)
                })).to(.1, {
                    scale: 1.1 * e
                }).to(.1, {
                    scale: e
                }).call(function() {
                    n.isPlay = !1;
                }).repeatForever(cc.tween().by(1, {
                    position: cc.v2(0, 15)
                }).by(1, {
                    position: cc.v2(0, -15)
                })).start()) : n && n.doDestory();
            }), r.default.getInstance().gameView.appendSprite({
                url: "texture/battle/shadow",
                root: r.default.getInstance().gameView.bottom,
                pos: this.node.getPosition().add(cc.v2(0, -20))
            }).then(function(e) {
                n.isDestory ? r.default.getInstance().gameView.removeSprite(e.node) : (n.shadow = e.node, 
                e.node.active = !0, e.node.scale = .4, e.node.angle = 0, e.node.zIndex = -2);
            });
        }
    }, e.prototype.doDestory = function() {
        var e = r.default.getInstance().gameView.items.indexOf(this);
        -1 < e && r.default.getInstance().gameView.items.splice(e, 1), this.sprite && r.default.getInstance().gameView.removeSprite(this.sprite.node), 
        this.skeleton && r.default.getInstance().gameView.removeSkeleton(this.skeleton.node), 
        this.shadow && r.default.getInstance().gameView.removeSprite(this.shadow), this.node.destroy();
    }, e.prototype.update = function() {
        var e, t = this;
        this.isDestory || this.isPlay || !r.default.getInstance().gameView || (this.type == c.ItemType.BUFFER ? 0 < (e = r.default.getInstance().gameView.players.map(function(e) {
            return {
                mag: e.node.getPosition().sub(t.node.getPosition()).mag(),
                target: e
            };
        }).sort(function(e, t) {
            return e.mag - t.mag;
        })).length && e[0].mag < 40 && (this.isDestory = !0, s.default.getInstance().playAudio("吃到道具"), 
        e[0].target.doBuffer(this.data), this.doDestory()) : this.type == c.ItemType.CHRISTMAS ? 0 < (e = r.default.getInstance().gameView.players.map(function(e) {
            return {
                mag: e.node.getPosition().sub(t.node.getPosition()).mag(),
                target: e
            };
        }).sort(function(e, t) {
            return e.mag - t.mag;
        })).length && e[0].mag < 40 && (this.isDestory = !0, e[0].target.model.openid == GA.Info.openId && (s.default.getInstance().playAudio("吃到道具"), 
        d.default.getInstance().hasItem(this.data) || d.default.getInstance().getItem(this.data)), 
        this.doDestory()) : this.type == c.ItemType.NEWYEAR && 0 < (e = r.default.getInstance().gameView.players.map(function(e) {
            return {
                mag: e.node.getPosition().sub(t.node.getPosition()).mag(),
                target: e
            };
        }).sort(function(e, t) {
            return e.mag - t.mag;
        })).length && e[0].mag < 40 && (this.isDestory = !0, e[0].target.model.openid == GA.Info.openId && (s.default.getInstance().playAudio("吃到道具"), 
        d.default.getInstance().hasItem(this.data) || d.default.getInstance().getItem(this.data)), 
        this.doDestory()));
    }, e.prototype.getBufferUrl = function(e) {
        switch (e) {
          case l.BufferType.加血:
            return "buffer/加血/skeleton";

          case l.BufferType.加攻:
            return "buffer/加攻/skeleton";

          case l.BufferType.加速:
            return "buffer/加速/skeleton";

          default:
            return "buffer/加血/skeleton";
        }
    }, e.prototype.getChristmasUrl = function(e, t) {
        if (0 == e) return "image/ui/金币@2x";
        if (1 == e) return "image/ui/钻石@2x";
        if (2 == e) return "image/ui/碎片@2x";
        if (3 == e) switch (t) {
          case 13:
            return "image/eggs/塞罗凹凸曼@2x";

          case 17:
            return "image/eggs/迪迦凹凸曼@2x";

          case 18:
            return "image/eggs/盖亚凹凸曼@2x";

          case 19:
            return "image/eggs/戴拿凹凸曼@2x";

          default:
            return "image/eggs/塞罗凹凸曼@2x";
        }
    }, e.prototype.getNewYearUrl = function(e, t) {
        return 0 == e ? "image/ui/金币@2x" : 1 == e ? "image/ui/钻石@2x" : 2 == e ? "image/ui/碎片@2x" : 4 == e ? 3e3 <= t ? "texture/armOlympic/" + t : 2e3 <= t ? "image/arm_draw/" + (t - 2e3) : 1e3 <= t ? "image/arm3/" + (t - 1e3) : "image/arm/" + t : void 0;
    }, a([ p ], e);
}(cc.Component));

n.default = h;